function ajax({type="get", url="", data={}, success, error, timeout=10000, beforeComplete}={}){
    // 处理数据
    let str = "";
    for(let i in data){
        str += `${i}=${data[i]}&`
    }
    str = str.slice(0,-1);
    url = type==="get" ? url+"?"+str+"&__t__="+Date.now() : url;
    // 开启并配置ajax
    const xhr = new XMLHttpRequest();
    xhr.open(type, url);
    xhr.timeout = timeout;
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    // 监听事件
    xhr.onreadystatechange = function(){
        if(xhr.readyState === 2){
            beforeComplete && beforeComplete();
        }
    }
    xhr.onload = function(){
        if(xhr.status === 200){
            success && success(xhr.responseText);
        }else{
            error && error(xhr.status);
        }
    }
    xhr.ontimeout = function(){
        error && error("超时");
        xhr.abort();
    }
    // 发送数据
    xhr.send( type==="post" ? str : undefined );
}